package com.learn.hd.interview.jdk8;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zhanghaidong
 * @version v1.0
 * @description
 * @date 2019/6/27
 */
public class Lambda {

    public static void main(String[] args) {
        List<Person> list = new ArrayList<>();
        list.add(new Person("zha", 12, 1));
        list.add(new Person("www", 14, 2));
        list.add(new Person("fff", 34, 2));
        list.add(new Person("ggg", 19, 1));

        List<Person> collect = list.stream()
                .filter(p -> 1 == p.getSex())
                .collect(Collectors.toList());

        System.out.println(collect);

        // parallelStream背后的男人:ForkJoinPool
        collect = list.parallelStream().filter( p -> 2 == p.getSex()).collect(Collectors.toList());
        System.out.println(collect);
    }

    public static class Person {
        private String name;
        private int age;
        private int sex;

        public Person(String name, int age, int sex) {
            this.name = name;
            this.age = age;
            this.sex = sex;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public int getSex() {
            return sex;
        }

        public void setSex(int sex) {
            this.sex = sex;
        }

        @Override
        public String toString() {
            return "Person{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    ", sex=" + sex +
                    '}';
        }
    }
}
